package com.google.code.timetrail.gui;

import javax.swing.JPanel;
import javax.swing.JButton;

import com.google.code.timetrail.backend.Control;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

public class TitleFrame extends JPanel{
    private Control myControl;
    private JPanel myCD;
    public TitleFrame(Control gameControl, JPanel cd) {
        this.myControl = gameControl;
        this.myCD = cd;
        this.setPreferredSize(new Dimension(500, 400));
        setLayout(null);
        
        JButton btnNewGame = new JButton("New Game");
        btnNewGame.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                myCD.add(new StartupFrame(myControl, myCD), "TakeMove");
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.last(myCD);
            }
        });
        btnNewGame.setBounds(114, 266, 83, 23);
        add(btnNewGame);
        
        JButton btnLoadGame = new JButton("Load Game");
        btnLoadGame.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    myCD.add(new LoadGameFrame(myControl, myCD), "TakeMove");
                } catch (ClassNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                CardLayout cd = (CardLayout) myCD.getLayout();
                cd.last(myCD);
            }
        });
        btnLoadGame.setBounds(217, 266, 89, 23);
        add(btnLoadGame);
    }

}
